package cn.tedu.boot08.controller;

import cn.tedu.boot08.entity.Banner;
import cn.tedu.boot08.mapper.BannerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.File;
import java.util.List;

/**
 * @author 作者：HeShaoShuai
 * @Email 邮箱：2569819541@qq.com
 * @Date 日期：2023/5/16 9:16
 * @Package 包名：cn.tedu.boot08.controller
 * @Project 项目名：JavaSE
 * @Version 1.0
 */
@RestController
public class BannerController {
	@Autowired
	BannerMapper mapper;
	@RequestMapping("/insert")
	public void insert(@RequestBody Banner banner){
		System.out.println("banner = " + banner);
		mapper.insert(banner);
        /*
        use birddb;
        create table banner(id int primary key auto_increment,
        url varchar(255),des varchar(100));
        * */
	}
	@RequestMapping("/select")
	public List<Banner> select(){
		return mapper.select();
	}
	@RequestMapping("/delete")
	public void delete(int id){
		//通过轮播图对象的id查询到图片的路径
		String url = mapper.selectUrlById(id);
		new File("D:/IDEA/files"+url).delete();
		mapper.deleteById(id);
	}
}
